#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
string header, message;
string res, tmp;
vector<string> codes;
map<string, int> mp;
string get(int n, int len) {
  string res(len, '0');
  per(i, len - 1, 0) {
    res[i] = n % 2 + '0';
    n /= 2;
  }
  return res;
}
void init_codes() {
  rep(i, 1, 7) {
    rep(j, 0, (1 << i) - 2) { codes.push_back(get(j, i)); }
  }
  rep(i, 0, codes.size() - 1) mp[codes[i]] = i;
}
void solve() {
  res.clear();
  getline(cin, message);
  int l = 0;
  while (true) {
    while (l + 3 > message.size()) {
      getline(cin, tmp);
      message += tmp;
    }
    int len = 0;
    rep(i, 0, 2) len = len * 2 + message[l + i] - '0';
    l += 3;
    if (len == 0) break;
    string end(len, '1');
    string x;
    while (true) {
      while (l + len > message.size()) {
        getline(cin, tmp);
        message += tmp;
      }
      x = message.substr(l, len);
      l += len;
      if (x == end) break;
      res.push_back(header[mp[x]]);
    }
  }
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init_codes();
  while (getline(cin, header)) {
    solve();
  }
  return 0;
}